package com.ckc.mq.producer;

import com.ckc.mq.consumer.Consumer01;
import com.ckc.mq.msg.Message01;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class Producer01 {

    private static final Logger logger = LoggerFactory.getLogger(Producer01.class);

    @Autowired
    RabbitTemplate rabbitTemplate;

    public void syncSend() {
        Message01 message01 = new Message01();
        message01.setId(UUID.randomUUID().toString().replace("-", ""));
        logger.info("发送的消息: {}" , message01);
        rabbitTemplate.convertAndSend(Message01.EXCHANGE, Message01.ROUTING_KEY, message01);
    }

    public void send02() {
        Message01 message01 = new Message01();
        message01.setId(UUID.randomUUID().toString().replace("-", ""));
        logger.info("发送的消息: {}" , message01);
        rabbitTemplate.convertAndSend(Message01.EXCHANGE, message01);
    }
}
